<template>
  <el-container class="height100">
    <el-header>
      <el-row>
        <el-col :span="4">
          <div class="grid-content bg-purple">
            <router-link to="/">
              <img src="../assets/logo.png" alt srcset>
            </router-link>
          </div>
        </el-col>
        <el-col :span="16">
          <div class="grid-content bg-purple-light">电商后台管理系统</div>
        </el-col>
        <el-col :span="4">
          <div class="grid-content bg-purple">
            <el-button @click="logout" type="info" plain>退出</el-button>
          </div>
        </el-col>
      </el-row>
    </el-header>

    <el-container>
      <el-aside width="200px">
        <!-- router=true 作用是激活以index属性值为值的跳转path -->
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          :router="router"
        >
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="userlist">
                <i class="el-icon-menu"></i>用户列表
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>

          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>权限管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="roles">
                <i class="el-icon-menu"></i>
                角色列表
              </el-menu-item>
              <el-menu-item index="rights">
                <i class="el-icon-menu"></i>权限列表
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-main>

        <router-view/>

      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data(){
    return {
      router:true
    }
  },
  
  methods: {
    logout() {
      localStorage.removeItem("token");
      this.$message({ message: "退出成功", type: "success" });
      this.$router.push("/login");
    }
  },

  mounted() {
    // 在页面渲染之前判断有没有token
    // 如果没有，直接调回到登录 不提示
    if (!localStorage.getItem("token")) {
      this.$router.push("/login");
    }

    this.$axios({
      url: "users?pagenum=1&pagesize=10",
      method: "get",
      headers: { Authorization: localStorage.getItem("token") }
    }).then(backdata => {
      // console.log(backdata);
    });
  }
};
</script>

<style>
.el-menu {
  width: 200px;
  height: 100%;
}

.el-submenu {
  text-align: left;
}

.height100 {
  height: 100%;
}

.el-header {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.bg-purple-light {
  font-size: 25px;
  color: white;
}
</style>
